﻿using Adnc.Application.Shared.Services;
using Adnc.Infra.IRepositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WYT.Sys.Application.Contracts.Dtos.Brand;
using WYT.Sys.Application.Contracts.Services;
using WYT.Sys.Repository.Entities;

namespace WYT.Sys.Application.Services
{
    public class BrandAppService : AbstractAppService, IBrandAppService
    {
        private readonly IEfRepository<BrandInfor> _brandInforEfRepository;

        private readonly IEfRepository<BrandGroup> _brandGroupEfRepository;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="brandInforEfRepository"></param>
        /// <param name="brandGroupEfRepository"></param>
        public BrandAppService(IEfRepository<BrandInfor> brandInforEfRepository
            , IEfRepository<BrandGroup> brandGroupEfRepository)
        {
            _brandGroupEfRepository = brandGroupEfRepository;
            _brandInforEfRepository = brandInforEfRepository;    
        }

        /// <summary>
        /// 获取品牌介绍信息
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<AppSrvResult<List<BrandInforDto>>> GetBandInforList()
        {
            var brand = await _brandGroupEfRepository.Where(x => x.IsDeleted == false).OrderBy(x => x.Sort).ToListAsync();
            var infor = await _brandInforEfRepository.Where(x => x.IsDeleted == false).ToListAsync();

            return brand.Join(infor, x => x.Id, c => c.GroupId, (g, i) => new BrandInforDto
            {
                Id = i.Id,
                Sort = i.Sort,
                Type = i.Type,
                Url = i.Url,
                GroupId = g.Id
            }).ToList();
        }

        /// <summary>
        /// 获取品牌介绍分组
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<AppSrvResult<List<BrandGroupDto>>> GetBrandGroupList()
        {
            return await _brandGroupEfRepository.Where(x => x.IsDeleted == false)
                .Select(x => new BrandGroupDto
                {
                    Id = x.Id,
                    Name = x.Name,
                    Sort = x.Sort
                }).ToListAsync();
        }
    }
}
